package com.rollCall.controller;


import cn.hutool.core.util.StrUtil;
import com.rollCall.common.constant.MessageConstant;
import com.rollCall.entity.vo.LoginVo;
import com.rollCall.entity.result.Result;
import com.rollCall.service.AdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class AdminController {
    private final AdminService adminService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String token = adminService.login(loginVo);
        return StrUtil.isBlank(token) ? Result.error(MessageConstant.PASSWORD_ERROR) : Result.success(token);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    public Result<Void> register(@RequestBody LoginVo loginVo) {
        adminService.register(loginVo);
        return Result.success();
    }
}
